const dayjs = require('dayjs')
const pool = require('../../mysql/Dao/sql')
const ProductService ={
    AddProduct:async (data)=>{
        try{
         
            const params =data
            const sql='insert into product(title,introduction,detail,cover,editTime) values(?,?,?,?,?)'
            return  pool(sql,params)
        }catch(err){
            return {
                err:err,code:400
            }
        }

    },
    GetAllProduct:async()=>{
        try{
            const params = []
            const sql = 'select * from product'
            return pool(sql,params)
        }
        catch(err){
            return {err:err,code:400}
        }
    },
    EditProduct:async(data)=>{
        try{
            const params =[data.title,data.introduction,data.detail,data.cover,data.editTime,data.id]
            const sql='update product set title=?,introduction=?,detail=?,cover=?,editTime=? where id=?'
            return pool(sql,params)
        }
        catch(err){
            return {err:err,code:400}
        }
    },
    Deleteproduct:async (data)=>{
        try{
            const params=[data]
            const sql = 'delete from product where id = ?'
            return pool(sql,params)
        }
        catch(err){
            return {
                err:err,
                code:400
            }
        }
    },
}

module.exports=ProductService